<template>
	<view>
		<view class="card-view">
			<view class="row-start cell-view">
				<view class="label">收款账户</view>
				<input type="number" v-model="account" placeholder="输入收款人绑定的手机号" placeholder-class="placeholder-css" class="input-css" />
			</view>
			<view class="row-start cell-view">
				<view class="label">转账金额</view>
				<input type="number" v-model="money" placeholder="输入要转账的权益分金额" placeholder-class="placeholder-css" class="input-css" />
			</view>
			<view class="remark">可转账权益分{{minAmount}}={{maxAmount}}元</view>
		</view>
		
		
		<view class="column-div submit" @click="submit">确认转账</view>
		 
		<pay-password v-if="payMode" @cancel="payMode = false" @confirm="equityTransfer" confirmText="确认转账"></pay-password>
		
	</view>
</template>

<script>
	
	export default {
		
		data() {
			return {
				account: '',
				money: '',
				maxAmount: 0,
				minAmount: 0,
				payMode: false
			}
		},
		onLoad(options) {
			this.account = options.account || ''
		},
		onShow() {
			this.getUserBalance_fun()
		},
		methods: {
			equityTransfer (payPassword) {
				this.$api.showLoading()
				this.$api.globalUtil.requestAjax({
					url: '/AccountBalanceApi/equityTransfer',
					method: 'POST',
					data: {
						phone: this.account,
						amount: this.money,
						payPassword: payPassword
					},
					success: (res) => {
						console.log("res", res)
						if (!res.data.success) return this.$api.msg(res.data.errMsg);
						
					},
				
					complate: () => this.$api.hideLoading()
				});
			},
			submit () {
				let isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
				let reg = /^([1-9][0-9]{10})$/;
				if (!this.account)return this.$api.msg('输入收款人绑定的手机号')
				if (!reg.test(this.account))return this.$api.msg('输入收款人的有效手机号')
				if (!this.money)return this.$api.msg('输入要转账的权益分金额')
				if (!isNum.test(this.money)) return this.$api.msg('请输入有效金额')
				if (this.money > this.maxAmount) return this.$api.msg('最高转账金额' + (this.maxAmount).toFixed(2))
				this.payMode = true
			},
			getUserBalance_fun() {
				this.$api.showLoading()
				this.$api.globalUtil.requestAjax({
					url: '/AccountBalanceApi/convertibleEquity',
					method: 'POST',
					success: (res) => {
						console.log("res", res)
						this.maxAmount = res.data.response.dollar || 0;
						this.minAmount = res.data.response.point.toFixed(2) || 0;
					},
					complate: () => this.$api.hideLoading()
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.submit{
		width: 600upx;
		height: 90upx;
		background: #FE5E49;
		border-radius: 45upx;
		margin: auto;
		margin-top: 110upx;
		font-size: 34upx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
	.card-view {
		width: calc(100% - 60upx);
		margin: 30upx auto;
		background: #FFFFFF;
		border-radius: 10upx;
		padding: 0 30upx;

		.cell-view {
			width: 100%;
			padding: 50upx 0;
			border-bottom: 1px solid #EEEEEE;

			&:last-child {
				border-bottom: none;
			}

			.label {
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				margin-right: 49upx;
			}

			.input-css {
				flex: 1;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
			}

			.placeholder-css {
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #BFBFBF;
			}

		}

		.remark {
			width: 100%;
			text-align: left;
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FE5E49;
			padding: 30upx 0;
		}
	}

</style>
